<?php

    
    //长内容分页
    $sub_content=SpLongBody($zhangjie['content'],1000,"[nextpage]");
    //$sub_content=article_addpage($zhangjie['content'],'1000');

    $sub_content=article_fenpage($sub_content,array('zid'=>$zid,'moduleid'=>$moduleid,'type'=>4),$page);
    
    
function article_fenpage($article,$id,$page)
{	
	$str=array();
	foreach($id as $k=>$v){
		$str[]="{$k}=$v";
	}
	$str=implode('&amp;',$str);
  $artinfo=explode("[nextpage]",$article);//根据字符串确定段落
  $pages=count($artinfo);//确定段落数
  $tempurla="";
  $fenyedh="";
 // echo $pages;
//=======================================分页导航
			//显示总页数
if ($pages>1){

$fenyedh= $fenyedh."<div align='center'>共有".$pages."页 ";
$substart=$page-2;
$sybend=$page+2;
if ($substart<=1 ){
$substart=1;
}
if ($sybend>=$pages ){
$sybend=$pages;
}
//显示分页数
$first=1;
$prev=$page-1;
if($prev=="0") $prev=1;
$next=$page+1;
if($next>$pages) $next=$pages;
$last=$pages;
//
$fenyedh= $fenyedh."<a href='?".$str."'>首页</a>&nbsp;";
$fenyedh= $fenyedh."<a href='?".$str."&page=".$prev."'>上一页</a>&nbsp;";
for ($i=$substart;$i<$page;$i++){
$fenyedh= $fenyedh."<a href='?".$str."&page=".$i."'>[".$i."]</a>&nbsp;";
}
$fenyedh= $fenyedh."[".$page."]";
for ($i=$page+1;$i<=$sybend;$i++){
	$fenyedh= $fenyedh."<a href='?".$str."&page=".$i."'>[".$i."]</a>&nbsp;";}
}

$fenyedh= $fenyedh."<a href='?".$str."&page=".$next."'>下一页</a>&nbsp;";
$fenyedh= $fenyedh."<a href='?".$str."&page=".$last."'>尾页</a>";
$fenyedh= $fenyedh."</div>";

//=======================================分页导航end
return $artinfo[$page-1]."<br>".$fenyedh; 
}


/**
 *  文档自动分页
 *
 * @access    public
 * @param     string  $mybody  内容
 * @param     string  $spsize  分页大小
 * @param     string  $sptag  分页标记
 * @return    string
 */
function SpLongBody($mybody, $spsize, $sptag)
{
    if(strlen($mybody) < $spsize)
    {
        return $mybody;
    }
    $mybody = stripslashes($mybody);
    $bds = explode('<', $mybody);
    $npageBody = '';
    $istable = 0;
    $mybody = '';
    foreach($bds as $i=>$k)
    {
        if($i==0)
        {
            $npageBody .= $bds[$i]; continue;
        }
        $bds[$i] = "<".$bds[$i];
        if(strlen($bds[$i])>6)
        {
            $tname = substr($bds[$i],1,5);
            if(strtolower($tname)=='table')
            {
                $istable++;
            }
            else if(strtolower($tname)=='/tabl')
            {
                $istable--;
            }
            if($istable>0)
            {
                $npageBody .= $bds[$i]; continue;
            }
            else
            {
                $npageBody .= $bds[$i];
            }
        }
        else
        {
            $npageBody .= $bds[$i];
        }
        if(strlen($npageBody)>$spsize)
        {
            $mybody .= $npageBody.$sptag;
            $npageBody = '';
        }
    }
    if($npageBody!='')
    {
        $mybody .= $npageBody;
    }
    return addslashes($mybody);
}
    